class Solution {
public:
    bool check(vector<int> &nums,vector<int> &target,int nPos){

        if(nPos+target.size()>nums.size()){

            return false;
        }
        int nTarPos=0;
        for(int i=0;i<static_cast<int>(target.size());++i){

            if(nums[nPos+i]!=target[i]){

                return false;
            }
        }

        return true;  
    }
    bool canChoose(vector<vector<int>>& groups, vector<int>& nums) {
        
        int nPos=0;

         for (int i=0;i<static_cast<int>(nums.size()) && nPos<groups.size();){

            if(check(nums,groups[nPos],i)){

                i+=groups[nPos].size();
                nPos++;
            }
            else{

                ++i;
            }
        }
        return nPos==static_cast<int>(groups.size());       
    }
};
